import Form.LNode;
import Matter.Link;
import Methods.LeafSize;
import Methods.Solution;

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in =new Scanner(System.in);
        System.out.print("请输入一个以‘#’号标明空子树信息的二叉树的先根遍历序列创造二叉树：");
        String a=in.next();
        Link link=new Link(a);
        System.out.print("它的先序遍历为：");
        link.preRootTraverse(link.getRoot());
        System.out.println();
        System.out.print("它的中序遍历为：");
        link.inRootTraverse(link.getRoot());
        System.out.println();
        System.out.print("它的后序遍历为：");
        link.postRootTraverse(link.getRoot());
        System.out.println();
        LNode root=link.getRoot();
        LeafSize leafSize=new LeafSize();
        System.out.println("它的叶子结点数为："+leafSize.LeafSize(root));
        Solution solution=new Solution();
        System.out.println("它的高度为："+solution.height(root));
        System.out.print("请输入你要删除的结点：");
        String deletet=in.next();
        char deletetl=deletet.charAt(0);
        link.delete(deletetl);
        System.out.print("删除子树后二叉树先序遍历为：");
        link.preRootTraverse(link.getRoot());
        System.out.println();
        System.out.print("删除子树后二叉树中序遍历为：");
        link.inRootTraverse(link.getRoot());
        System.out.println();
        System.out.print("删除子树后二叉树后序遍历为：");
        link.postRootTraverse(link.getRoot());
        System.out.println();
        System.out.println("它的叶子结点数为："+leafSize.LeafSize(root));
        System.out.println("它的高度为："+solution.height(root));
        System.out.print("请输入你要添加的子树的先序遍历结果：");
        String a1=in.next();
        System.out.print("请输入你要添加的子树的中序遍历结果：");
        String a2=in.next();
        Link b=new Link(a1,a2,0,0,a1.length());
        System.out.print("请输入你要添加子树的结点：");
        String a3=in.next();
        Object a4=a3.charAt(0);
        link.insert(a4,b);
        System.out.print("添加子树后二叉树先序遍历为：");
        link.preRootTraverse(link.getRoot());
        System.out.println();
        System.out.print("添加子树后二叉树中序遍历为：");
        link.inRootTraverse(link.getRoot());
        System.out.println();
        System.out.print("添加子树后二叉树后序遍历为：");
        link.postRootTraverse(link.getRoot());
        System.out.println();
        System.out.println("它的叶子结点数为："+leafSize.LeafSize(root));
        System.out.println("它的高度为："+solution.height(root));
    }
}
